package cn.lzh.controller;

import cn.lzh.service.LargefileService;
import cn.lzh.service.UserService;
import cn.lzh.tool.RespJson;
import cn.lzh.tool.Token;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@RestController
@RequestMapping({"/api/fore/user"})
public class UserForeController {
    @Autowired
    LargefileService largeFileService;
    @Autowired
    UserService userService;


    //更新密码
    @PostMapping({"/updatePwd"})
    public Map<String, Object> updatePwd(String pwd) {
        Map<String, Object> umap = new HashMap();
        int uid = Token.getUid();//获取用户的id
        if (uid == -1) { //如果id=-1表示未登录
            return RespJson.pack(401, "未登录 ...", "");
        } else {
            umap.put("id", uid);
            umap.put("password", pwd);
            this.userService.update(umap);
            return RespJson.pack(200, "更新密码成功", "");
        }
    }

    @PostMapping("/updateInfo")
    public Map<String, Object> updateInfo(String nickname, String phone) {
        Map<String, Object> map = new HashMap();
        int uid = Token.getUid();//获取用户的id
        if (uid == -1) {
            return RespJson.pack(401, "未登录 ...", "");
        } else {
            map.put("id", uid);
            map.put("nickname", nickname);
            map.put("phone", phone);
             userService.update(map);
            return RespJson.pack(200, "更新用户信息成功", "");
        }
    }


}
